/**
 * Created by CL on 2017/5/15.
 */
var token=getCookie('token');
if(token){
    tokenTologin(token);
}
else{
    $(".index-button").show();
    $(".user-message").hide();
}
function tokenTologin(token) {
    $.ajax(
        {
            type: "post",
            url: top.server_url+"/users/tokenToLogin",
            dataType: "json",
            data: {
                token: token,
                'app_sid': 'huoma'
            },
            success: function (data) {
                //console.log(data);
                if (data.status == 200) {
                    if( data.payload.appInfo[0].vipInfo != undefined && data.payload.appInfo[0].vipInfo.huomaAmount != undefined && data.payload.appInfo[0].vipInfo.huomaAmount.can_use == 1) {
                        sessionStorage.setItem('user',token);
                        sessionStorage.setItem('phone',data.payload.account);
                        sessionStorage.setItem('recommender',data.payload.appInfo[0].hasRecommender);
                        sessionStorage.setItem('uid',data.payload.uid);
                        $(".index-button").hide();
                        $(".user-message").show();
                        $(".user-id").html(getCookie('account'));
                    } else {
                        var r = confirm('您还未是会员，请购买会员！');
                        if(r) {
                            top.location.href = ''; //购买页面
                        }
                    }
                }
                else {
                    alert(data.err);
                }
            }
        }
    )
}
if(action=='login'){
    $("#tan").css('display','block');
    $(".zhao").css('display','block');
    $(".zhao").animate({
            opacity:0.7
        },
        700);
    $(".absolute").attr('src','login.html');
    $(".absolute").slideToggle(600);
}
$("#user-link").click(function () {
    location.href="codemain.html";
})